#include "CVolume.h"



int vol_main (double newVolume)
{
	HRESULT hr;
	bool decibels = false;
	bool scalar = true;


	// -------------------------
	CoInitialize(NULL);
	IMMDeviceEnumerator *deviceEnumerator = NULL;
	hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
	IMMDevice *defaultDevice = NULL;

	hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
	deviceEnumerator->Release();
	deviceEnumerator = NULL;

	IAudioEndpointVolume *endpointVolume = NULL;
	hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
	defaultDevice->Release();
	defaultDevice = NULL; 

	// -------------------------
	float currentVolume = 0;
	//endpointVolume->GetMasterVolumeLevel(&currentVolume);
	//printf("Current volume in dB is: %f\n", currentVolume);

	//hr = endpointVolume->GetMasterVolumeLevelScalar(&currentVolume);
	//printf("Current volume as a scalar is: %f\n", currentVolume);
	/*if (decibels)
	{
		hr = endpointVolume->SetMasterVolumeLevel((float)newVolume, NULL);
	}
	else if (scalar)
	{*/

	hr = endpointVolume->SetMasterVolumeLevelScalar((float)newVolume, NULL);
	
	endpointVolume->Release();

	CoUninitialize();
	return 0;
}